<?php

/**
 * pagina php richiamata dalla POST Ajax per verificare se l'utente esiste
 * 
 * @author Stefano Poncini
 * @param string username $_POST
 * @return int
 */
 
require(__DIR__ . '/../inc/global.inc.php');

$sql = "SELECT username from user where username LIKE '%".$_REQUEST['term']."%'";


$stmt = DB::getDBO()->prepare($sql);
$stmt->execute();

// loop through each zipcode returned and format the response for jQuery
$data = array();

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    $data[] = array('label' => $row['username']);
}


// jQuery wants JSON data
echo json_encode($data);
flush();
?>